home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdlib.h> // on NeXT, at least
- #include <string.h> // on NeXT, at least
-
- typedef unsigned char uBYTE;
- typedef unsigned long dim;
-
- struct _implane
- {dim mwidth,mheight,
- iwidth,iheight;
- uBYTE *im;
- };
- typedef struct _implane implane;
- enum TURNS { T_NONE,T_RIGHT,T_LEFT };
-
- extern planealloc();
-
- void rotateBm( dim *wid, dim *ht, implane *r, implane *g, implane *b, enum TURNS t)
- {
- dim x,y,w,h;
- implane Out;
- register uBYTE *pIn,*pOut;
- uBYTE *work;
-
- w = *wid, h = *ht;
- work = malloc(h);
- planealloc(&Out, w, h);
- switch (t) {
-
- case T_RIGHT:
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = r->im + r->mwidth * ( r->mheight -1) + y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn -= r->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, r->im, w*h);
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = g->im + g->mwidth * ( r->mheight -1) + y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn -= g->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, g->im, w*h);
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = b->im + b->mwidth * ( r->mheight -1) + y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn -= b->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, b->im, w*h);
- break;
-
- case T_LEFT:
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = r->im + r->mwidth - 1 - y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn += r->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, r->im, w*h);
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = g->im + g->mwidth - 1 - y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn += g->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, g->im, w*h);
- pOut = Out.im;
- for( y=0; y<w; y++ ) {
- pIn = b->im + b->mwidth - 1 - y;
- for( x=0; x<h; x++ ) {
- work[x] = *pIn;
- pIn += b->mwidth;
- }
- bcopy(work, pOut, h);
- pOut += h;
- }
- bcopy( Out.im, b->im, w*h);
- break;
-
- default: /* T_NONE (or something else) */
- /* probably an internal error, but ignore for now */
- break;
- }
- *wid = h, *ht = w;
- free(Out.im);
- free(work);
- }
-